<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="船名" prop="shipName">
        <el-input
          v-model="queryParams.shipName"
          placeholder="请输入船名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="船舶编码" prop="shipCode">
        <el-input
          v-model="queryParams.shipCode"
          placeholder="请输入船舶编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basicInformation:ship:add']"
        >新增
        </el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['basicInformation:ship:edit']"-->
<!--        >修改-->
<!--        </el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['basicInformation:ship:remove']"
        >批量删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['basicInformation:ship:import']"
        >导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basicInformation:ship:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="setPrint"
          v-hasPermi="['frontierEvent:ship:export']"
        >打印
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="shipList" @selection-change="handleSelectionChange" id="tableList">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主建id" align="center" prop="id" v-if="false"/>
      <!--      <el-table-column label="数据状态" align="center" prop="state"/>-->
      <el-table-column label="在线状态" align="center" prop="isOnline">
        <template slot-scope="scope">
          <el-tooltip placement="top" content="在线" effect="dark" v-if="scope.row.isOnline === true">
            <img src="../../../../public/image/car/green-lamp.png"/>
          </el-tooltip>
          <el-tooltip placement="top" content="离线" effect="dark" v-if="scope.row.isOnline === false">
            <img src="../../../../public/image/car/red-lamp.png"/>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="定位" align="center" prop="isOnline">
        <template slot-scope="scope">
          <el-button v-if="scope.row.isOnline !== null"
                     size="mini"
                     type="text"
                     @click="handleOpenMap(scope.row,1)"
          >定位
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="终端名称" align="center" prop="equipmentName"/>
      <el-table-column label="终端编号" align="center" prop="equipmentNumber"/>
      <el-table-column label="船名" align="center" prop="shipName"/>
      <el-table-column label="船舶所有人名称" align="center" prop="pensionName"/>
      <el-table-column label="船舶编码" align="center" prop="shipCode"/>
      <el-table-column label="船长" align="center" prop="captain"/>
      <el-table-column label="辖区代码" align="center" prop="jurisdictionCode"/>
      <el-table-column label="主机总功率" align="center" prop="power"/>
      <el-table-column label="作业类型" align="center" prop="workType" :formatter="workTypeFormat"/>
      <el-table-column label="联系电话" align="center" prop="contactNumber"/>
      <el-table-column label="所属部门" align="center" prop="deptName"/>
<!--      <el-table-column label="所有人证件号" align="center" prop="certificateNumber"/>-->
<!--      <el-table-column label="船舶类型" align="center" prop="shipType" :formatter="shipTypeFormat"/>-->
      <el-table-column label="图片" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="showImage(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['basicInformation:ship:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['basicInformation:ship:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改船舶信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="数据状态" prop="state">
              <el-select v-model="form.state" placeholder="请选择数据状态">
                <el-option
                  v-for="dict in stateOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="船名" prop="shipName" label-width="110px">
              <el-input v-model="form.shipName" placeholder="请输入船名" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="船舶所有人名称" prop="pensionName" label-width="110px">
              <el-input v-model="form.pensionName" placeholder="请输入船舶所有人名称" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="船舶编码" prop="shipCode" label-width="110px">
              <el-input v-model="form.shipCode" placeholder="请输入船舶编码" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="船长" prop="captain" label-width="110px">
              <el-input v-model="form.captain" placeholder="请输入船长" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="辖区代码" prop="jurisdictionCode" label-width="110px">
              <el-input v-model="form.jurisdictionCode" placeholder="请输入辖区代码" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="主机总功率" prop="power" label-width="110px">
              <el-input v-model="form.power" placeholder="请输入主机总功率" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="作业类型" prop="workType">
              <el-select v-model="form.workType" placeholder="请选择作业类型">
                <el-option
                  v-for="dict in workTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="contactNumber" label-width="110px">
              <el-input v-model="form.contactNumber" placeholder="请输入联系电话" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所有人证件号" prop="certificateNumber" label-width="110px">
              <el-input v-model="form.certificateNumber" placeholder="请输入所有人证件号" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="船籍" prop="shipStatus" label-width="110px">
              <el-input v-model="form.shipStatus" placeholder="请输入船籍" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="航区" prop="navigationArea" label-width="110px">
              <el-input v-model="form.navigationArea" placeholder="请输入航区" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="总吨位" prop="tonnage" label-width="110px">
              <el-input v-model="form.tonnage" placeholder="请输入总吨位" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证书编号" prop="certificateCode" label-width="110px">
              <el-input v-model="form.certificateCode" placeholder="请输入证书编号" :disabled="stateShow"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="终端设备编码" prop="equipmentNumber">
              <el-input v-model="form.equipmentNumber" readonly style="width:144px"/>
              <el-button type="primary" v-model="form.terminalId" @click="selectTerminal" :disabled="stateShow">选择终端设备
              </el-button>
              <el-button type="primary" @click="unBundling" :disabled="stateShow" v-show="form.terminalId !== undefined">解绑
              </el-button>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="终端设备名称" prop="equipmentName">
              <el-input v-model="form.equipmentName" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="船舶所有人地址" prop="address" label-width="110px">
          <el-input v-model="form.address" placeholder="请输入内容" :disabled="stateShow"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark" label-width="110px">
          <el-input v-model="form.remark" type="textarea" :disabled="stateShow" placeholder="请输入备注"/>
        </el-form-item>
        <el-form-item label="附件" prop="equipmentName">
          <div>
            <el-upload class="upload-file"
                       drag
                       :action="fileRequestPath"
                       multiple
                       :before-upload="handleBeforeAvatarUpload"
                       :on-success="handleSuccess"
                       :headers="bindUploadAccessToken"
                       :on-remove="handleRemove"
                       :file-list="fileList">
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
            <div class="attach-show-con"
                 id="caseRegisterImg2" v-viewer>
              <div class="avatarimg" v-for="(item, index) in showUmEvtAttchList" :key="index">
                <img style="cursor: pointer;"
                     :src="`${item.url}`"
                >
                <span>{{item.name}}</span>
              </div>
            </div>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible" title="预览" class="imgss" height="800" z-index="20">
      <viewer :images="imgs">
        <img v-for="src in imgs" :key="src.url" :src="src.url">
      </viewer>
      <!--    <img :src="value" style="display: block; max-width: 100%; margin: 0 auto;">-->
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport + '&shipType=' + upload.shipType"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport"/>
          是否更新已经存在的数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="titleTerminal" :visible.sync="openTerminal" width="800px" append-to-body>
      <el-form :model="queryTerminalParams" ref="queryTerminalForm" :inline="true" v-show="showSearchTerminal"
               label-width="68px">
        <el-form-item label="设备名称" prop="equipmentName">
          <el-input
            v-model="queryTerminalParams.equipmentName"
            placeholder="请输入设备名称"
            clearable
            size="small"
            @keyup.enter.native="handleQueryTerminal"
          />
        </el-form-item>
        <el-form-item label="设备编号" prop="equipmentNumber">
          <el-input
            v-model="queryTerminalParams.equipmentNumber"
            placeholder="请输入设备编号"
            clearable
            size="small"
            @keyup.enter.native="handleQueryTerminal"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryTerminal">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetTerminalQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="myTable">
      <el-table v-loading="loading" :data="terminalList" @selection-change="handleSelectionChangeTerminal">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="主建id" align="center" prop="id" v-if="false"/>
        <el-table-column label="设备名称" align="center" prop="equipmentName"/>
        <el-table-column label="设备编号" align="center" prop="equipmentNumber"/>
      </el-table>
      </div>
      <pagination
        v-show="totalTerminal>0"
        :total="totalTerminal"
        :page.sync="queryTerminalParams.pageNum"
        :limit.sync="queryTerminalParams.pageSize"
        @pagination="getTerminalList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="okTerminal">确 定</el-button>
        <el-button @click="cancelTerminal">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="'地图'"
               :fullscreen="true"
               :visible="openMap"
               :close-on-click-modal="false"
               class="dialog_collect"
               @open="handleOpenDialog"
               @close="handleCloseDialog">
      <section class="dialog_body">
        <common-map
          ref="map"
          style="height: calc(100vh - 110px)"
          @map-click="ShowDetail"
          :isTool="false"
          :toolbarSelectVisible="false"
        >
        </common-map>
      </section>
      <boat-detail
        :visible='showBoatDialog'
        @close="showDetailDialog = -1"
        ref="boatDetail">
      </boat-detail>
    </el-dialog>
  </div>
</template>

<script>
  import {
    unBundling,
    listShip,
    getShip,
    delShip,
    addShip,
    updateShip,
    exportShip,
    importTemplate
  } from '@/api/basicInformation/shipY'
  import { getToken } from '@/utils/auth'
  import { listTerminal } from '@/api/basicInformation/terminal'
  import boatDetail from '@/views/onemap/Detail/boatDetail'
  import 'viewerjs/dist/viewer.css'
  import Viewer from 'v-viewer'
  import Vue from 'vue'

  Vue.use(Viewer)

  export default {
    name: 'ShipY',
    components: {
      boatDetail
    },
    computed: {
      bindUploadAccessToken() {
        return { 'Authorization': `Bearer ` + getToken() }
      },
      showBoatDialog() {
        return this.showDetailDialog === 2
      }
    },
    data() {
      return {
        stateOptions: [],
        workTypeOptions: [],
        map: null,
        showDetailDialog: -1,
        openMap: false,
        rowData: {},
        marker: [],
        fileList: [],
        isLt50M: '',
        fileRequestPath: process.env.VUE_APP_BASE_API + '/common/upload',
        showUmEvtAttchList: [],
        umEvtAttchList: [],
        removeUmEvtAttachList: [],
        newUmEvtAttachList: [],
        idsTerminal: [],
        terminalNames: [],
        terminalNumbers: [],
        // 显示搜索条件
        showSearchTerminal: true,
        totalTerminal: 0,
        terminalList: [],
        titleTerminal: '选择终端设备',
        openTerminal: false,
        fileUrl: process.env.VUE_APP_BASE_API + '/files/view?id=', // 上传的图片服务器地址,
        queryTerminalParams: {
          pageNum: 1,
          pageSize: 10,
          equipmentName: undefined,
          equipmentNumber: undefined,
          terminalType: '3',
          isBinding: '1'
        },
        dialogVisible: false,
        imgs: [
          {
            url: 'http://192.168.20.113:8080/files/view?id=60b0996d78098f1deff7465c',
            title: '图片1'
          },
          {
            url: 'http://192.168.20.113:8080/files/view?id=60b0996d78098f1deff7465c',
            title: '图片2'
          }
        ],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        names: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 船舶信息表格数据
        shipList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 船舶类型字典
        shipTypeOptions: [],

        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: '',
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 船只类型
          shipType: '1',
          // 设置上传的请求头部
          headers: { Authorization: 'Bearer ' + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + '/basicInformation/ship/importData'
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          shipName: undefined,
          shipCode: undefined,
          shipType: 1,
          orderByColumn: 'id',
          isAsc: 'desc'
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          equipmentNumber: [
            { required: true, message: '请绑定终端', trigger: 'change' }
          ],
          shipName: [
            {required: true, message: "船舶名字不能为空", trigger: "blur"},
            {min: 0, max: 30, message: '长度在 0 到 30 个字符', trigger: 'blur'}
          ],
          shipCode: [
            {required: true, message: "船舶编码不能为空", trigger: "blur"},
            {min: 0, max: 50, message: '长度在 0 到 50 个字符', trigger: 'blur'}
          ],
          certificateNumber: [
            {required: true, message: '所有人证件号不能为空', trigger: 'blur'},
            {
              pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
              message: "请输入正确格式的所有人证件号",
              trigger: "blur"
            }
          ],
          contactNumber: [
            {required: true, message: "联系电话不能为空", trigger: "blur"},
            {
              pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
              message: "请输入正确格式的联系电话",
              trigger: "blur"
            }
          ]
        }
      }
    },
    created() {
      this.getList()
      this.getDicts('ship_data_status').then(response => {
        this.stateOptions = response.data
      })
      this.getDicts('ship_oper_type').then(response => {
        this.workTypeOptions = response.data
      })
      this.getDicts('ship_type').then(response => {
        this.shipTypeOptions = response.data
      })
    },
    methods: {
      stateFormat(row, column) {
        return this.selectDictLabel(this.stateOptions, row.state)
      },
      workTypeFormat(row, column) {
        return this.selectDictLabel(this.workTypeOptions, row.workType)
      },
      /**
       * @author: mi.liu@topevery.club
       * @Date: 2019/7/8 15:44
       * @description: 图片上传前，做限制
       */
      handleBeforeAvatarUpload(file) {
        const index = file.name.lastIndexOf('.')
        const suffix = file.name.substr(index + 1) // map3

        const isJPEG = (suffix === 'jpeg' || suffix === 'JPEG')
        const isPNG = (suffix === 'png' || suffix === 'PNG')
        const isJPG = (suffix === 'jpg' || suffix === 'JPG')

        if (!(isJPG || isJPEG || isPNG)) {
          this.$message.error('上传的文件格式只能是PNG、JPG、JPEG!')
          return false
        }

        if (isJPG || isPNG || isJPEG) {
          this.isLt50M = file.size / 1024 / 1024 < 50
          if (!this.isLt50M) {
            this.$message.error('上传图片大小不能超过 20MB！')
            return false
          }
        }

      },
      /**
       * @author: mi.liu@topevery.club
       * @Date: 2019/7/8 15:51
       * @description: 图片上传成功
       */
      handleSuccess(res, file) {
        const attach = {}
        attach.id = res.id
        attach.name = file.name
        attach.url = process.env.VUE_APP_BASE_API + '/files/view?id=' + res.id

        // 修改的时候 删除的附件添加到 removeUmEvtAttachList
        if (this.form.id !== null) {
          this.newUmEvtAttachList.push(attach)
        }
        this.showUmEvtAttchList.push(attach)

      },
      /**
       * @author: mi.liu@topevery.club
       * @Date: 2019/7/8 15:50
       * @description: 删除附件
       */
      handleRemove(file, fileList) {

        // 修改的时候 删除的附件添加到 removeUmEvtAttachList
        if (this.form.id !== null) {
          this.newUmEvtAttachList = this.newUmEvtAttachList.filter((item) => {
            return item.name !== file.name
          })
        }
        // 删除上传后的附件 展示情况
        this.showUmEvtAttchList = this.showUmEvtAttchList.filter((item) => {
          return item.name !== file.name
        })

        //判断船舶原始附件是否有删除，只有删除了原始附件才去删除此船舶原来的附件
        var numNow = this.umEvtAttchList.length
        this.umEvtAttchList = this.umEvtAttchList.filter((item) => {
          return item.name !== file.name
        })
        if (this.umEvtAttchList.length !== numNow) {
          this.removeUmEvtAttachList.push({
            id: file.id
          })
        }
      },
      /**
       * @author: mi.liu@topevery.club
       * @Date: 2019/7/8 15:51
       * @description: 图片放大器
       */
      handleMagnify() {
        // Viewer.noConflict()
        this.$nextTick(() => {
          const ViewerDom = document.getElementById('caseRegisterImg')

          if (this.flag) {
            this.viewer.destroy()
          }
          this.viewer = new Viewer(ViewerDom, {
            viewed() {
              this.viewer.update()
            },
            // 相关配置项
            zIndex: 99999999999
          })
          this.flag = true
        })
      },
      setPrint() {
        // var html = document.getElementById("tableList").innerHTML;
        var w = window.open(location.href)
        // var style = w.document.createElement("style");
        // style.type = "text/css";
        // style.innerText = `打印内容元素的样式...`;
        var tableStr = '<table style=\'width:100%;\'><tr><td style=\'text-align: center;\'>数据状态</td><td style=\'text-align: center;\'>船名</td><td style=\'text-align: center;\'>船舶所有人名称</td><td style=\'text-align: center;\'>船舶编码</td><td style=\'text-align: center;\'>船长</td><td style=\'text-align: center;\'>辖区代码</td><td style=\'text-align: center;\'>主机总功率</td><td style=\'text-align: center;\'>作业类型</td><td style=\'text-align: center;\'>联系电话</td><td style=\'text-align: center;\'>所有人证件号</td><td style=\'text-align: center;\'>船舶类型</td></tr>'
        for (var i = 0; i < this.shipList.length; i++) {
          var state = this.shipList[i].state === null ? '' : this.shipList[i].state
          var shipName = this.shipList[i].shipName === null ? '' : this.shipList[i].shipName
          var pensionName = this.shipList[i].pensionName === null ? '' : this.shipList[i].pensionName
          var shipCode = this.shipList[i].shipCode === null ? '' : this.shipList[i].shipCode
          var captain = this.shipList[i].captain === null ? '' : this.shipList[i].captain
          var jurisdictionCode = this.shipList[i].jurisdictionCode === null ? '' : this.shipList[i].jurisdictionCode
          var power = this.shipList[i].power === null ? '' : this.shipList[i].power
          var workType = this.shipList[i].workType === null ? '' : this.shipList[i].workType
          var contactNumber = this.shipList[i].contactNumber === null ? '' : this.shipList[i].contactNumber
          var certificateNumber = this.shipList[i].certificateNumber === null ? '' : this.shipList[i].certificateNumber
          var shipType = this.selectDictLabel(this.shipTypeOptions, this.shipList[i].shipType)
          tableStr += '<tr><td style=\'text-align: center;\'>' + state + '</td><td style=\'text-align: center;\'>' + shipName + '</td><td style=\'text-align: center;\'>' + pensionName + '</td><td style=\'text-align: center;\'>' + shipCode + '</td><td style=\'text-align: center;\'>' + captain + '</td><td style=\'text-align: center;\'>' + jurisdictionCode + '</td><td style=\'text-align: center;\'>' + power + '</td><td style=\'text-align: center;\'>' + workType + '</td><td style=\'text-align: center;\'>' + contactNumber + '</td><td style=\'text-align: center;\'>' + certificateNumber + '</td><td style=\'text-align: center;\'>' + shipType + '</td></tr>'
        }
        tableStr += '</table>'
        w.document.body.innerHTML = tableStr
        w.document.close()
        w.print()
        w.close()
      },
      getTerminalList() {
        this.loading = true
        listTerminal(this.queryTerminalParams).then(response => {
          this.terminalList = response.rows
          this.totalTerminal = response.total
          this.loading = false
        })
      },
      okTerminal() {
        if (this.idsTerminal.length > 1) {
          this.msgInfo('只能绑定一个终端设备')
        } else if (this.idsTerminal.length === 1) {
          this.form.terminalId = this.idsTerminal[0]
          this.form.equipmentName = this.terminalNames[0]
          this.form.equipmentNumber = this.terminalNumbers[0]
          this.openTerminal = false
        } else {
          this.msgInfo('请选择终端设备')
        }
      },
      cancelTerminal() {
        this.openTerminal = false
      },
      handleQueryTerminal() {
        this.queryTerminalParams.pageNum = 1
        this.getTerminalList()
      },
      resetTerminalQuery() {
        this.resetForm('queryTerminalForm')
        this.handleQueryTerminal()
      },
      // 多选框选中数据
      handleSelectionChangeTerminal(selection) {
        this.idsTerminal = selection.map(item => item.id)
        this.terminalNames = selection.map(item => item.equipmentName)
        this.terminalNumbers = selection.map(item => item.equipmentNumber)
      },
      selectTerminal() {
        this.openTerminal = true
        this.handleQueryTerminal()
      },
      unBundling() {
        let _thisSelf = this
        this.$confirm('是否确认解绑终端设备', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return unBundling({ terminalId: _thisSelf.form.terminalId })
        }).then(() => {
          this.msgSuccess('解绑成功')
          this.open = false
          this.getList()
        })
      },
      /** 查询船舶信息列表 */
      getList() {
        this.loading = true
        listShip(this.queryParams).then(response => {
          this.shipList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 船舶类型字典翻译
      shipTypeFormat(row, column) {
        return this.selectDictLabel(this.shipTypeOptions, row.shipType)
      },
      // 取消按钮
      cancel() {
        this.fileList = []
        this.showUmEvtAttchList = []
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          state: undefined,
          shipName: undefined,
          pensionName: undefined,
          shipCode: undefined,
          captain: undefined,
          jurisdictionCode: undefined,
          power: undefined,
          workType: undefined,
          contactNumber: undefined,
          certificateNumber: undefined,
          address: undefined,
          shipStatus: undefined,
          navigationArea: undefined,
          terminalId: undefined,
          terminalIdOld: undefined,
          equipmentNumber: undefined,
          equipmentName: undefined,
          shipType: 2,
          tonnage: undefined,
          remark: undefined,
          certificateCode: undefined,
          delFlag: undefined,
          createById: undefined,
          createBy: undefined,
          createTime: undefined,
          updateById: undefined,
          updateBy: undefined,
          updateTime: undefined
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.names = selection.map(item => item.shipName)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset()
        this.open = true
        this.title = '添加船舶信息'
      },
      showImage(row) {
        this.imgs = []
        const _this = this
        if (row.showUmEvtAttchList && row.showUmEvtAttchList.length > 0) {
          row.showUmEvtAttchList.forEach(item => {
            this.imgs.push({
              url: _this.fileUrl + item.id,
              title: item.name
            })
          })
          this.dialogVisible = true
          // this.$viewer.show()
        } else {
          this.msgSuccess('没有附件')
        }
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset()
        const id = row.id || this.ids
        getShip(id).then(response => {
          this.fileList = []

          this.form = response.data
          this.form.terminalIdOld = this.form.terminalId
          this.showUmEvtAttchList = this.form.showUmEvtAttchList
          this.umEvtAttchList = this.form.showUmEvtAttchList
          if (this.showUmEvtAttchList.length > 0) {
            for (const i in this.showUmEvtAttchList) {
              this.fileList.push({
                id: this.showUmEvtAttchList[i].id,
                name: this.showUmEvtAttchList[i].name
                // url: process.env.VUE_APP_BASE_API + "/files/view?id=" + this.showUmEvtAttchList[i].id
              })
              this.showUmEvtAttchList[i].url = process.env.VUE_APP_BASE_API + '/files/view?id=' + this.showUmEvtAttchList[i].id
            }
          }
          this.open = true
          this.title = '修改船舶信息'
        })
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              this.form.removeUmEvtAttachList = this.removeUmEvtAttachList
              this.form.newUmEvtAttachList = this.newUmEvtAttachList
              updateShip(this.form).then(response => {
                this.msgSuccess('修改成功')
                this.open = false
                this.getList()
              })
            } else {
              this.form.shipType = '1'
              this.form.showUmEvtAttchList = this.showUmEvtAttchList
              addShip(this.form).then(response => {
                this.msgSuccess('新增成功')
                this.open = false
                this.getList()
              })
            }
            this.showUmEvtAttchList = []
            this.removeUmEvtAttachList = []
            this.newUmEvtAttachList = []
            this.umEvtAttchList = []
            this.fileList = []
          }
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids
        const names = row.shipName || this.names
        this.$confirm('是否确认删除船名为"' + names + '"的数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return delShip(ids)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
      },
      /** 导出按钮操作 */
      handleExport(row) {
        const queryParams1 = {...this.queryParams}
        queryParams1.pageSize = 9999
        queryParams1.pageNum = 1
        queryParams1.ids = row.userId || this.ids
        this.$confirm(queryParams1.ids.length > 0 ? '是否确认导出所选数据项' : '是否确认导出所有船舶信息数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return exportShip(queryParams1)
        }).then(response => {
          this.download(response.msg)
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = '执法船只导入'
        this.upload.open = true
      },
      /** 下载模板操作 */
      importTemplate() {
        importTemplate().then(response => {
          this.download(response.msg)
        })
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false
        this.upload.isUploading = false
        this.$refs.upload.clearFiles()
        this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
        this.getList()
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit()
      },
      handleOpenMap(row, e) {
        this.openMap = true
        this.rowData = row
      },
      handleOpenDialog() {
        this.$nextTick(() => {
          this.map = this.$refs.map.map
          this.marker.push({
            coordinates: [this.rowData.x, this.rowData.y],
            id: this.rowData.id,
            title: this.rowData.shipName,
            target: 'fisher',
            animate: true,
            stopEvent: true,
            iconUrl: '/image/map/fisher.png',
            item: this.rowData
          })
          this.$refs.map.showMarkerFeature(this.marker, false, 'fisher')
          this.$refs.map.map.getMap().getView().animate({
            center: [this.rowData.x, this.rowData.y],
            duration: 500
          })
        })
      },
      ShowDetail(e) {
        this.$refs.boatDetail.handleShowCaseInfo(e, this.map)
        this.showDetailDialog = 2
      },
      handleCloseDialog() {
        this.showDetailDialog = -1
        this.marker = []
        this.openMap = false
        this.$forceUpdate()
      }
    }
  }
</script>
<style lang="scss" scoped>
  ::v-deep .myTable {
    .el-table__fixed-header-wrapper {
      .el-checkbox__inner {
        display: none !important;
      }
    }
  }
  ::v-deep .el-form-item .el-select .el-input {
    width: 270px !important;
  }
  .imgss img {
    width: 250px !important;
    height: 250px !important;
    /*float: left;*/
  }

  .attach-show-con {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;

    .avatarimg {
      width: 100px;
      height: 100px;
      padding-bottom: 5px;
      margin: 0 6px 6px 0;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      overflow: hidden;
      line-height: 30px;
      border: 1px solid #eee;
      font-size: 12px;
      text-align: center;

      span {
        display: block;
        line-height: 14px;
        margin-top: 5px;
        width: 100%;
      }

      img {
        width: 100%;
        height: 60px;
        display: block;
      }

      video {
        width: 100px;
        height: 60px;
        display: block;
      }

      audio {
        width: 100px;
        display: block;
        height: 40px;
        margin: 10px 0;

        &:focus {
          outline: none;
        }
      }
    }
  }
</style>
